﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using GaiNo.Core.Data;
using GaiNo.WS.Core.Models;
namespace GaiNo.WS.Core.Services
{
    public partial class SiteList : ISiteList
    {
        private string _keyword = string.Empty;
        private IPager _pager = null;
        #region IObjectList<SiteInfo> 成员

        public IList<SiteEntity> GetList()
        {
            StringBuilder strSql = new StringBuilder();
            if (_pager == null)
            {
                strSql.Append("select * FROM [Site]");
                strSql.Append(" where ");
                strSql.Append(getSelectWhereString());
            }
            else
            {
                _pager.TableName = "[Site]";
                _pager.PrimaryKey = "[UId]";
                _pager.StrGetFields = "*";
                _pager.StrWhere = getSelectWhereString();
                strSql.Append(_pager.GetSqlSentence());
            }
            IList<SiteEntity> list = new List<SiteEntity>();
            using (IDataReader dataReader = SqlHelper.ExecuteReader(strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(SiteEntityBind.ReaderBind(dataReader));
                }
            }
            return list;
        }

        public string Keyword
        {
            get
            {
                if (string.IsNullOrEmpty(_keyword))
                    return "1=1";
                return "[UId]=" + _keyword  + " or " + "[BannerUrl] like '%" + _keyword + "%'" + " or " + "[Created] like '%" + _keyword + "%'" + " or " + "[Currency] like '%" + _keyword + "%'" + " or " + "[LogoUrl] like '%" + _keyword + "%'" + " or " + "[Name] like '%" + _keyword + "%'" + " or " + "[Status] like '%" + _keyword + "%'" + " or " + "[Title] like '%" + _keyword + "%'";
            }
            set
            {
                _keyword = value;
            }
        }
        public IPager Pager
        {
            set { _pager = value; }
        }

        #endregion
    }
}



